package cn.tedu.kcircle.passport.adapter.handler;

import cn.tedu.kcircle.common.handler.GlobalControllerExceptionHandler;
import cn.tedu.kcircle.common.restful.JsonResult;
import cn.tedu.kcircle.common.restful.ResponseCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class CustomControllerExceptionHandler extends GlobalControllerExceptionHandler {
    @ExceptionHandler
    public JsonResult<Void> handleAccessDeniedException(AccessDeniedException e){
        String message="您没有权限访问该页面，请联系管理员";
        log.error(message,e);
        return JsonResult.failed(ResponseCode.ERROR_FORBIDDEN,message);
    }
}
